# '''
#  * @ author     ：廖传港
#  * @ date       ：Created in 2020/12/4 19:03
#  * @ description：
#  * @ modified By：
#  * @ ersion     :
#  * @File        : experiment.py
# '''
#
#
# # -*- coding: utf-8 -*-
# #
# # h, w = 50,100
# #
# # # 对于长宽不相等的图片，找到最长的一边
# # # longest_edge = max(h, w)
# # shortest_edge = min(h, w)
# # print(shortest_edge)
# # # 计算短边需要增加多上像素宽度使其与长边等长
# # if h > shortest_edge:
# #     dh = shortest_edge - h
# #     top = dh // 2
# #     bottom = dh - top
# #     print(bottom)
# # elif w > shortest_edge:
# #     dw = w - shortest_edge
# #     left = dw // 2
# #     right = dw - left
# #     print(right)
# # else:
# #     pass
#
#
# # # 获取图像尺寸
# # h, w = 200,400
# #
# # # 对于长宽不相等的图片，找到最长的一边
# # longest_edge = max(h, w)
# # # longest_edge = max(h, w)
# #
# # # 计算短边需要增加多上像素宽度使其与长边等长
# # if h < longest_edge:
# #     dh = longest_edge - h
# #     top = dh // 2
# #     bottom = dh - top
# #     print(bottom)
# # elif w < longest_edge:
# #     dw = longest_edge - w
# #     left = dw // 2
# #     right = dw - left
# #     print(right)
# #
# # else:
# #     pass
#
#
# # import cv2
# #
# # img = cv2.imread("D:/picture/p/s.jpg")
# #
# # # 裁剪为300x300像素
# # img = img[0:300,0:300]
# # cv2.imshow("img",img)
# # cv2.waitKey()
#
# #
# # #该文件是对图片做预处理，主要有resize_image()函数和灰度化
# # import os
# # import cv2
# # import numpy as np
# #
# # IMAGE_SIZE = 100
# #
# # def resize_image(image, height=IMAGE_SIZE, width=IMAGE_SIZE):
# #     top, bottom, left, right = (0, 0, 0, 0)
# #
# #     h, w, _= image.shape
# #
# #     shortest_edge = max(h, w)
# #     if h > shortest_edge:
# #         dh = h - shortest_edge
# #         top = dh // 2
# #         bottom = dh - top
# #     elif w > shortest_edge:
# #         dw = w - shortest_edge
# #         left = dw // 2
# #         righ = dw - left
# #     else:
# #         pass
# #
# #     BLACK = [0, 0, 0]
# #
# #     constant = cv2.copyMakeBorder(image, top, bottom, left, right, cv2.BORDER_CONSTANT, value=BLACK)
# #
# #     return cv2.resize(constant, (height, width))
# #
# #
# # if __name__ == '__main__':
# #     path_name1 = "C:/Users/LCG/Desktop/test/"#这个为你想要预处理文件的路径
# #     i = 0
# #     for dir_item in os.listdir(path_name1):
# #         full_path = os.path.abspath(os.path.join(path_name1, dir_item))
# #         i += 1
# #         image = cv2.imread(full_path)       #读取出照片
# #         image = resize_image(image)         #将图片大小转为64*64
# #         image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)     #将图片转为灰度图
# #         cv2.imwrite(full_path,image)
#
#
# # *-*coding=utf8*-*
# '''
# Created on 2019年1月2日
#
# @author: admin
# '''
#
# # import numpy as np
# # import matplotlib.pyplot as plt
# #
# # x = np.arange(-10, 10, 0.001)
# # y = 1 / (1 + np.exp(-x))
# # plt.plot(x,y)
# # plt.suptitle(r'$y=\frac{1}{1+e^{-x}}$', fontsize=20)
# # plt.grid(color='gray')
# # plt.grid(linewidth='1')
# # plt.grid(linestyle='--')
# #
# # plt.show()
#
# #
# # import numpy as np
# # import matplotlib.pyplot as plt
# #
# # x = np.arange(-10, 10, 0.001)
# # y = max(0,x)
# # plt.plot(x,y)
# # plt.suptitle(r'$y=\frac{1}{1+e^{-x}}$', fontsize=20)
# # plt.grid(color='gray')
# # plt.grid(linewidth='1')
# # plt.grid(linestyle='--')
# #
# # plt.show()
#
# '''
#
# for i in range(1, 10):
#     alpha = i
#     beta = alpha * 10
#     x = np.arange(-4, 4, 0.001)
#     y = (1 - np.exp(-x * alpha)) / (1 + np.exp(-x * beta))
#     plt.subplot(3, 3, i)
#     plt.plot(x, y, label=r'$\alpha={0}$'.format(alpha))
#     plt.plot(x, y, label=r'$\beta={0}$'.format(beta))
#     plt.legend(loc=0)
#
# plt.suptitle(r'$\frac{1-e^{-x*\alpha}}{1+e^{-x*\beta}}$', fontsize=20)
# plt.show()
# '''
# # import numpy as np
# # import matplotlib.pyplot as plt
# #
# # fig = plt.figure(figsize=(6, 4))
# # ax = fig.add_subplot(111)
# # x = np.arange(-10, 10)
# # y = np.where(x < 0, 0, x)  # 满足条件(condition)，输出x，不满足输出y
# # plt.xlim(-11, 11)
# # plt.ylim(-11, 11)
# # ax = plt.gca()  # get current axis 获得坐标轴对象
# # ax.spines['right'].set_color('none')
# # ax.spines['top'].set_color('none')  # 将右边 上边的两条边颜色设置为空 其实就相当于抹掉这两条边
# # ax.xaxis.set_ticks_position('bottom')
# # ax.yaxis.set_ticks_position('left')  # 指定下边的边作为 x 轴   指定左边的边为 y 轴
# # ax.spines['bottom'].set_position(('data', 0))  # 指定 data  设置的bottom(也就是指定的x轴)绑定到y轴的0这个点上
# # ax.spines['left'].set_position(('data', 0))
# #
# # plt.plot(x, y, label='ReLU', linestyle="-", color="darkviolet")  # label为标签
# # plt.legend(['ReLU'])
# # plt.savefig('ReLU.png', dpi=500)  # 指定分辨
# # plt.show()
#
# # import numpy as np
# # import matplotlib.pyplot as plt
# #
# # fig = plt.figure(figsize=(6, 4))
# # ax = fig.add_subplot(111)
# # x = np.arange(-5, 5)
# # # y = np.where(x < 0, 0, x)  # 满足条件(condition)，输出x，不满足输出y
# # y = 1 / (1 + np.exp(-x))
# # plt.xlim(-3, 3)
# # plt.ylim(-3, 3)
# # ax = plt.gca()  # get current axis 获得坐标轴对象
# # ax.spines['right'].set_color('none')
# # ax.spines['top'].set_color('none')  # 将右边 上边的两条边颜色设置为空 其实就相当于抹掉这两条边
# # ax.xaxis.set_ticks_position('bottom')
# # ax.yaxis.set_ticks_position('left')  # 指定下边的边作为 x 轴   指定左边的边为 y 轴
# # ax.spines['bottom'].set_position(('data', 0))  # 指定 data  设置的bottom(也就是指定的x轴)绑定到y轴的0这个点上
# # ax.spines['left'].set_position(('data', 0))
# #
# # plt.plot(x, y, label='ReLU', linestyle="-", color="darkviolet")  # label为标签
# # plt.legend(['ReLU'])
# # plt.savefig('ReLU.png', dpi=500)  # 指定分辨
# # plt.show()
#
#
#
#
#
#
#
#
#
# # -*- coding: utf-8 -*-
# import argparse
# import math
# import sys
# import time
# import copy
#
# import keras
# from keras.models import Sequential, Model
# from keras.layers import Dense, Dropout, Flatten, Activation, BatchNormalization, regularizers
# from keras.layers.noise import GaussianNoise
# from keras.layers import Conv2D, MaxPooling2D
# from keras import backend as K
# from keras.callbacks import ModelCheckpoint, EarlyStopping
# from keras.utils.np_utils import to_categorical
# K.set_image_dim_ordering('th')
# print(K.image_data_format())
#
# ## required for efficient GPU use
# import tensorflow as tf
# from keras.backend import tensorflow_backend
# config = tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True))
# session = tf.Session(config=config)
# tensorflow_backend.set_session(session)
# ## required for efficient GPU use
#
# import os
# import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
# import numpy as np # linear algebra
#
# # define path to save model
# model_path = './fm_cnn_BN.h5'
# # prepare callbacks
# callbacks = [
#     EarlyStopping(
#         monitor='val_acc',
#         patience=10,
#         mode='max',
#         verbose=1),
#     ModelCheckpoint(model_path,
#         monitor='val_acc',
#         save_best_only=True,
#         mode='max',
#         verbose=0)
# ]
#
#
# # get data
# test  = pd.read_csv('./fashion-mnist_test.csv')
# train = pd.read_csv('./fashion-mnist_train.csv')
# print('train shape: {}'.format(train.shape))
# print('test shape: {}'.format(test.shape))
#
# #reshape data
# y_train_CNN = train.ix[:,0].values.astype('int32') # only labels i.e targets digits
# X_train_CNN = np.array(train.iloc[:,1:].values).reshape(train.shape[0], 1, 28, 28).astype(np.uint8)# reshape to be [samples][pixels][width][height]
# print('train shape after reshape: {}'.format(X_train_CNN.shape))
#
# y_test_CNN = test.ix[:,0].values.astype('int32') # only labels i.e targets digits
# X_test_CNN = np.array(test.iloc[:,1:].values).reshape((test.shape[0], 1, 28, 28)).astype(np.uint8)
# print('test shape after reshape: {}'.format(X_test_CNN.shape))
#
# # one hot encode outputs
# y_train_CNN = to_categorical(y_train_CNN)
# y_test_CNN = to_categorical(y_test_CNN)
# num_classes = y_train_CNN.shape[1]
#
# # normalize inputs from 0-255 to 0-1
# X_train_CNN = X_train_CNN / 255
# X_test_CNN = X_test_CNN / 255
#
# #size of parameters
# batch_size = 128
# num_classes = 10
# epochs = 100
# filter_pixel=3
# noise = 1
# droprate=0.25
#
# # input image dimensions
# img_rows, img_cols = 28, 28
#
# input_shape = (1, img_rows, img_cols)
#
# #Start Neural Network
# model = Sequential()
# #convolution 1st layer
# model.add(Conv2D(64, kernel_size=(filter_pixel, filter_pixel), padding="same",
#                  activation='relu',
#                  input_shape=input_shape)) #0
# model.add(BatchNormalization())
# model.add(Dropout(droprate))#3
# #model.add(MaxPooling2D())
#
# #convolution 2nd layer
# model.add(Conv2D(64, kernel_size=(filter_pixel, filter_pixel), activation='relu',border_mode="same"))#1
# model.add(BatchNormalization())
# model.add(MaxPooling2D())
# model.add(Dropout(droprate))#3
#
# #convolution 3rd layer
# model.add(Conv2D(64, kernel_size=(filter_pixel, filter_pixel), activation='relu',border_mode="same"))#1
# model.add(BatchNormalization())
# model.add(MaxPooling2D())
# model.add(Dropout(droprate))#3
#
# #Fully connected 1st layer
# model.add(Flatten()) #7
# model.add(Dense(500,use_bias=False)) #13
# model.add(BatchNormalization())
# model.add(Activation('relu')) #14
# model.add(Dropout(droprate))      #15
#
# #Fully connected final layer
# model.add(Dense(10)) #8
# model.add(Activation('softmax')) #9
#
#
# model.compile(loss=keras.losses.categorical_crossentropy,
#               optimizer=keras.optimizers.RMSprop(),
#               metrics=['accuracy'])
#
# model.summary()
#
# #Save Model=ON
# history = model.fit(X_train_CNN, y_train_CNN,
#           batch_size=batch_size,
#           epochs=epochs,
#           verbose=1,
#           validation_data=(X_test_CNN, y_test_CNN),shuffle=True,callbacks=callbacks)
#
# score = model.evaluate(X_test_CNN, y_test_CNN, verbose=0)
#
# #print loss and accuracy
# print('Test loss:', score[0])
# print('Test accuracy:', score[1])



import numpy as np

import os
import random
import sys
import numpy as np
import cv2

#
# n = 4
# X = np.ones((n,n,3), dtype = np.int)
# print(X.shape)
#
#
# print(X)
# # image = np.pad(X, ((1, 1), (1, 1),), 'constant')  # ,constant_values 缺省，则默认填充均为0
# image = np.pad(X, ((0, 0),(1, 1),(1, 1)), 'constant')  # ,constant_values 缺省，则默认填充均为0
# print(image)
# print("image.shape=", image.shape)




full_path='D:\\python\\data\\test\\dog\\dog.4006.jpg'
image = cv2.imread(full_path,cv2.IMREAD_UNCHANGED)

print(image.shape)
print(image)

image = np.pad(image, ((1, 1), (1, 1), (0, 0)), 'constant')
print("image.shape=", image.shape)
print(image)
# X=np.array(image)
# print(X)
